<?php

namespace App\Listeners;

use App\Events\WDBillRecord;
use App\Repositories\Eloquent\FinanceBillRepository;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class WDBillRecordListener implements ShouldQueue
{

    public $queue = 'bill_record';

    public $billRepo;

    /**
     * Create the event listener.
     *
     * @param FinanceBillRepository $billRepository
     */
    public function __construct(FinanceBillRepository $billRepository)
    {
        //
        $this->billRepo = $billRepository;
    }

    /**
     * Handle the event.
     *
     * @param WDBillRecord $event
     * @return void
     */
    public function handle(WDBillRecord $event)
    {
        //
        $this->billRepo->createWDBillRecord($event->order);
    }

    /**
     * 处理任务失败
     *
     * @param WDBillRecord $event
     * @param  \Exception $exception
     * @return void
     */
    public function failed(WDBillRecord $event, $exception)
    {
        //
        Log::info('提现完成流水写入失败! 系统流水号['.$event->order->plat_no .']，错误信息:'.$exception->getMessage());
    }
}
